home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Science⁄Math
/
Scientist's Helper src
/
s.helper.5
/
regwnd.c
< prev
Wrap
C/C++ Source or Header
|
1986-02-06
|
16KB
|
623 lines
#include "all.h"
#include "regtabext.h"
LoadSg2() /*force load of segment*/
{
;
}
IndentRect( rPtr )
Rect *rPtr;
{
rPtr->bottom = rPtr->bottom-16;
rPtr->right = rPtr->right-16;
rPtr->top = rPtr->top+4;
rPtr->left = rPtr->left+4;
}
GetWndNumber( window )
WindowPtr window;
{
int i;
currentWindow = -1;
for ( i = 0; i < lastWindow; i++ ) {
if (theWindow[i] == window) {
currentWindow = i;
break;
} /* end if */
} /* end for */
}
ResizePRect()
{
pRect = theWindow[currentWindow]->portRect;
pRect.right = pRect.right - 15;
pRect.bottom = pRect.bottom - 15;
}
FindLine(position, text)
int position;
TEHandle text;
{
int i, j;
j = 0;
if( (*text)->nLines < 1 ) {
j = 0;
}
else if( position < (*text)->lineStarts[0] ) {
j = 0;
}
else if( position >= (*text)->lineStarts[ (*text)->nLines-1 ] ) {
j = (*text)->nLines;
}
else {
for( i=((*text)->nLines-1)-1; i>=0; i-- ) {
if( (position >= (*text)->lineStarts[i]) &&
(position < (*text)->lineStarts[i+1]) ) {
j = i;
break;
} /*end if between linestarts*/
} /*end for*/
} /* end if in interior line */
return(j);
}
IfOutScroll(text)
TEHandle text;
{
int pixelNum, bottomPixel, dv, amount, i;
char s[80];
pixelNum = (*text)->lineHeight * FindLine( (*text)->selEnd , text );
bottomPixel = topPixel[currentWindow] +
(theWindow[currentWindow]->portRect.bottom-theWindow[currentWindow]->portRect.top)-40;
if( !( ( pixelNum >= (topPixel[currentWindow]+(*text)->lineHeight) ) &&
( pixelNum <= (bottomPixel-(*text)->lineHeight) ) ) ) {
dv = bottomPixel-pixelNum;
TEScroll( 0, dv, text );
topPixel[currentWindow] = topPixel[currentWindow] - dv;
} /*end if*/
if( (*text)->nLines > 0 ) {
amount = ( 32767L * (long)topPixel[currentWindow] ) /
( (long)(*text)->nLines * (long)(*text)->lineHeight);
}
else {
amount = 0;
}
SetCtlValue( vScroll[currentWindow],amount);
}
DrawWindow()
{
Rect tRect;
ClipRect(&(theWindow[currentWindow]->portRect));
DrawGrowIcon(theWindow[currentWindow]);
DrawControls(theWindow[currentWindow]);
if ( (currentWindow == grWindow) || (currentWindow == edWindow) ){
/* now set up a clip area which excludes the scroll bars */
tRect = theWindow[currentWindow]->portRect;
tRect.bottom = tRect.bottom - 16;
tRect.right = tRect.right - 16;
/* now compensate for any scrolling which has been done */
OffsetRect(&tRect, theOrigin[currentWindow].h, theOrigin[currentWindow].v);
ClipRect(&tRect);
/* change the origin to compensate for any scrolling */
SetOrigin(theOrigin[currentWindow].h, theOrigin[currentWindow].v);
DrawStuff( currentWindow );
SetOrigin(0,0);
ClipRect(&(theWindow[currentWindow]->portRect)); /* reset the clip area */
} /*end if grwindow*/
else if ( (currentWindow == coWindow) || (currentWindow == prWindow ) ) {
DrawStuff( currentWindow );
}
}
ScrollBits()
{
Point oldOrigin;
int dh, dv, t1, t2, newTopPixel, newLeftPixel, i, j;
Rect tRect;
if (currentWindow == grWindow) {
ResizePRect();
oldOrigin = theOrigin[currentWindow];
t1 = (719 - theWindow[currentWindow]->portRect.right);
t2 = (373 - theWindow[currentWindow]->portRect.bottom);
theOrigin[currentWindow].h = ((long)t1 * (long)GetCtlValue(hScroll[currentWindow]))/32767L;
theOrigin[currentWindow].v = ((long)t2 * (long)GetCtlValue(vScroll[currentWindow]))/32767L;
dh = oldOrigin.h - theOrigin[currentWindow].h;
dv = oldOrigin.v - theOrigin[currentWindow].v;
theUpdateRgn = NewRgn();
ScrollRect( &pRect, dh, dv, theUpdateRgn);
/* have scrolled in junk... need to redraw */
SetOrigin(theOrigin[currentWindow].h, theOrigin[currentWindow].v);
OffsetRect(&(*theUpdateRgn)->rgnBBox,theOrigin[currentWindow].h, theOrigin[currentWindow].v);
ClipRect(&(*theUpdateRgn)->rgnBBox);
DrawStuff();
DisposeRgn(theUpdateRgn);
SetOrigin(0,0);
ClipRect(&(theWindow[currentWindow]->portRect));
} /*end if grWindow*/
else if (currentWindow == edWindow) {
ResizePRect();
ClipRect( &pRect );
DrawStuff();
ClipRect(&(theWindow[currentWindow]->portRect));
} /*end if edWindow*/
else if (currentWindow == coWindow) {
newTopPixel = (short) ( ( (long)(*coText)->nLines * (long)(*coText)->lineHeight
* (long)GetCtlValue(vScroll[currentWindow]) ) / 32767L);
newLeftPixel = (short) ( ( (long)windowWidth * (long)GetCtlValue(hScroll[currentWindow]) )
/ 32767L );
dv = -newTopPixel + topPixel[coWindow];
dh = -newLeftPixel + leftPixel[coWindow];
topPixel[coWindow] = newTopPixel;
leftPixel[coWindow] = newLeftPixel;
TEScroll( dh, dv, coText );
}
else if (currentWindow == prWindow) {
newTopPixel = (short) ( ( (long)(*prText)->nLines * (long)(*prText)->lineHeight
* (long)GetCtlValue(vScroll[currentWindow]) ) / 32767L);
newLeftPixel = (short) ( ( (long)windowWidth * (long)GetCtlValue(hScroll[currentWindow]) )
/ 32767L );
dv = -newTopPixel + topPixel[prWindow];
dh = -newLeftPixel + leftPixel[prWindow];
topPixel[prWindow] = newTopPixel;
leftPixel[prWindow] = newLeftPixel;
TEScroll( dh, dv, prText );
}
}
pascal void ScrollUp(whichControl,theCode)
ControlHandle whichControl;
int theCode;
{
if ( theCode == inUpButton ) {
SetCtlValue(whichControl,GetCtlValue(whichControl)-640);
ScrollBits();
}
}
pascal void TScrollUp(whichControl,theCode)
ControlHandle whichControl;
int theCode;
{
int amount;
if ( theCode == inUpButton ) {
if( whichControl==vScroll[coWindow] ) {
if( (*coText)->nLines==0 ) return;
amount = (2L * 32767L) / (long)(*coText)->nLines;
SetCtlValue(whichControl,GetCtlValue(whichControl)-amount);
}
else if( whichControl==vScroll[prWindow] ) {
if( (*prText)->nLines==0 ) return;
amount = (2L * 32767L) / (long)(*prText)->nLines;
SetCtlValue(whichControl,GetCtlValue(whichControl)-amount);
}
else if( whichControl==vScroll[edWindow] ) {
SetCtlValue(whichControl,GetCtlValue(whichControl)-8);
}
else if( whichControl==hScroll[edWindow] ) {
SetCtlValue(whichControl,GetCtlValue(whichControl)-1024);
}
else {
SetCtlValue(whichControl,GetCtlValue(whichControl)-640);
}
ScrollBits();
}
}
pascal void ScrollDown(whichControl,theCode)
ControlHandle whichControl;
int theCode;
{
int i;
long test;
if ( theCode == inDownButton ) {
test = (long)GetCtlValue(whichControl)+640L;
if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
ScrollBits();
}
}
pascal void TScrollDown(whichControl,theCode)
ControlHandle whichControl;
int theCode;
{
int amount, i;
long test;
if ( theCode == inDownButton ) {
if( whichControl==vScroll[coWindow] ) {
if( (*coText)->nLines==0 ) return;
amount = (2L * 32767L) / (long)(*coText)->nLines;
test = (long)GetCtlValue(whichControl)+(long)amount;
if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else if( whichControl==vScroll[prWindow] ) {
if( (*prText)->nLines==0 ) return;
amount = (2L * 32767L) / (long)(*prText)->nLines;
test = (long)GetCtlValue(whichControl)+(long)amount;
if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else if( whichControl==vScroll[edWindow] ) {
test = (long)GetCtlValue(whichControl)+8L;
if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else if( whichControl==hScroll[edWindow] ) {
test = (long)GetCtlValue(whichControl)+1024L;
if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else {
test = (long)GetCtlValue(whichControl)+640L;
if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
ScrollBits();
}
}
TPageScroll(code,amount)
int code, amount;
{
Point myPt;
int onePage, linesPerPage, i;
long test;
do {
GetMouse(&myPt);
if ( TestControl(whichControl,pass(myPt)) == code ) {
if( whichControl==vScroll[coWindow] ) {
linesPerPage = (theWindow[currentWindow]->portRect.bottom -
theWindow[currentWindow]->portRect.top) /
(*coText)->lineHeight;
if( (*coText)->nLines==0 ) return;
onePage = ( (long)(linesPerPage-2) * 32767L ) / (long)(*coText)->nLines;
if( amount<0 ) {
onePage = (-onePage);
}
test = (long)GetCtlValue(whichControl)+(long)onePage;
if( test<=0 ) {
i=0;
}
else if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else if( whichControl==vScroll[prWindow] ) {
linesPerPage = (theWindow[currentWindow]->portRect.bottom -
theWindow[currentWindow]->portRect.top) /
(*prText)->lineHeight;
if( (*prText)->nLines==0 ) return;
onePage = ( (long)(linesPerPage-2) * 32767L) / (long)(*prText)->nLines ;
if( amount<0 ) {
onePage = (-onePage);
}
test = (long)GetCtlValue(whichControl)+(long)onePage;
if( test<=0 ) {
i=0;
}
else if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else if( whichControl==vScroll[edWindow] ) {
onePage = 80;
if( amount<0 ) {
onePage = (-onePage);
}
test = (long)GetCtlValue(whichControl)+(long)onePage;
if( test<=0 ) {
i=0;
}
else if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else if( whichControl==hScroll[edWindow] ) {
onePage = 4096;
if( amount<0 ) {
onePage = (-onePage);
}
test = (long)GetCtlValue(whichControl)+(long)onePage;
if( test<=0 ) {
i=0;
}
else if( test<=32767 ) {
i = (int)test;
}
else {
i = 32767;
}
SetCtlValue(whichControl,i);
}
else {
SetCtlValue(whichControl,GetCtlValue(whichControl)+amount);
}
ScrollBits();
}
}
while (StillDown());
}
PageScroll(code,amount)
int code, amount;
{
Point myPt;
do {
GetMouse(&myPt);
if ( TestControl(whichControl,pass(myPt)) == code ) {
SetCtlValue(whichControl,GetCtlValue(whichControl)+amount);
ScrollBits();
}
}
while (StillDown());
}
DrawStuff()
{
PenState pState;
Rect tRect;
int i, j, top, left, hLast, vLast;
char s[cmdWordLen];
float x;
if (currentWindow == edWindow ) {
PenPat( black );
top = (GetCtlValue(vScroll[edWindow])/8)+1;
left =(GetCtlValue(hScroll[edWindow])/1024)+1;
hLast = (whichWindow->portRect.right-16)/100;
if(hLast>4) {
hLast=4;
}
vLast = (whichWindow->portRect.bottom-16)/15;
if(vLast>19) {
vLast=19;
}
for (i=0; i<hLast; i++) {
EraseRect( &(tabEd.name[i]) );
if( GoodCol(left+i)==0 ) {
MoveTo( tabEd.name[i].left+1, tabEd.name[i].bottom-2 );
DrawText( table.header.colName[left+i-1], 0,
strlen(table.header.colName[left+i-1]) );
}
} /*end for*/
for (i=0; i<vLast; i++) {
EraseRect( &(tabEd.row[i]) );
if( GoodRow(top+i)==0 ) {
IToS( (top+i), s );
MoveTo( tabEd.row[i].left+1, tabEd.row[i].bottom-2 );
DrawText( s, 0, strlen(s) );
}
} /*end for*/
for (i=0; i<vLast; i++) {
for (j=0; j<hLast; j++ ) {
EraseRect( &(tabEd.entry[i][j]) );
if( (GoodRow(top+i)==0) && (GoodCol(left+j)==0) ) {
GetTable( (top+i), (left+j), &x );
RToS( x, s );
MoveTo( tabEd.entry[i][j].left+1, tabEd.entry[i][j].bottom-2 );
DrawText( s, 0, strlen(s) );
}
} } /*end fors*/
i=tabEd.r - top;
j=tabEd.c - left;
if( tabEd.activeName) {
if( (j<0) || (j>=4) ) {
(*edText)->destRect = wayOffScreen;
(*edText)->viewRect = wayOffScreen;
TESetSelect( 0L, (long)(*edText)->teLength, edText );
TEDelete(edText);
tabEd.activeName=FALSE;
}
else {
(*edText)->destRect = tabEd.name[j];
ResizeEdBox();
TEUpdate( &((*edText)->destRect), edText );
}
} /*end if active name*/
else if (tabEd.activeEntry) {
if( (i<0) || (i>=19) || (j<0) || (j>=4) ) {
(*edText)->destRect = wayOffScreen;
(*edText)->viewRect = wayOffScreen;
TESetSelect( 0L, (long)(*edText)->teLength, edText );
TEDelete(edText);
tabEd.activeEntry=FALSE;
}
else {
(*edText)->destRect = tabEd.entry[i][j];
ResizeEdBox();
TEUpdate( &((*edText)->destRect), edText );
}
} /*end if active entry*/
}
else if (currentWindow == coWindow ) {
EraseRect( &((*coText)->viewRect) );
TEUpdate( &(theWindow[currentWindow]->portRect), coText );
}
else if (currentWindow == prWindow ) {
EraseRect( &((*prText)->viewRect) );
TEUpdate( &(theWindow[currentWindow]->portRect), prText );
}
else if (currentWindow == grWindow ) {
CopyBits( &grMap, &(theWindow[currentWindow]->portBits),
&(grMap.bounds), &(grMap.bounds), srcCopy, 0L );
}
}
void MoveScrollBars()
{
HideControl(vScroll[currentWindow]);
MoveControl(vScroll[currentWindow],theWindow[currentWindow]->portRect.right-15,
theWindow[currentWindow]->portRect.top-1);
SizeControl(vScroll[currentWindow],16,theWindow[currentWindow]->portRect.bottom-
theWindow[currentWindow]->portRect.top-13);
ShowControl(vScroll[currentWindow]);
HideControl(hScroll[currentWindow]);
MoveControl(hScroll[currentWindow],theWindow[currentWindow]->portRect.left-1,
theWindow[currentWindow]->portRect.bottom-15);
SizeControl(hScroll[currentWindow],theWindow[currentWindow]->portRect.right-
theWindow[currentWindow]->portRect.left-13,16);
ShowControl(hScroll[currentWindow]);
}
ResizeEdBox()
{
Rect tRect;
tRect = theWindow[edWindow]->portRect;
IndentRect( &tRect );
SectRect( &tRect, &((*edText)->destRect), &((*edText)->viewRect) );
}
GrowWnd(whichWindow)
WindowPtr whichWindow;
{
long longResult;
short height, width;
Rect tRect;
longResult = GrowWindow(whichWindow,pass(myEvent.where),&growRect);
if ( longResult == 0 )
return();
height = longResult >> 16;
width = longResult;
/* add the old "scroll bar area" to the update region so it will */
/* be redrawn (for when the window is enlarged) */
tRect = whichWindow->portRect;
tRect.left = tRect.right - 16;
InvalRect(&tRect);
tRect = whichWindow->portRect;
tRect.top = tRect.bottom - 16;
InvalRect(&tRect);
/* now draw the newly sized window */
SizeWindow(whichWindow,width,height,TRUE);
ClipRect(&(theWindow[currentWindow]->portRect));
MoveScrollBars();
DrawGrowIcon(whichWindow);
ResizePRect();
/* add the new "scroll bar area" to the update region so it will
be redrawn (for when the window is made smaller) */
tRect = whichWindow->portRect;
tRect.left = tRect.right - 16;
InvalRect(&tRect);
tRect = whichWindow->portRect;
tRect.top = tRect.bottom - 16;
InvalRect(&tRect);
if( currentWindow == coWindow ) {
tRect = theWindow[currentWindow]->portRect;
IndentRect( &tRect );
InvalRect(&tRect);
(*coText)->viewRect = tRect;
}
else if( currentWindow == prWindow ) {
tRect = theWindow[currentWindow]->portRect;
IndentRect( &tRect );
InvalRect(&tRect);
(*prText)->viewRect = tRect;
}
else if( currentWindow == edWindow ) {
ResizeEdBox();
InvalRect(&(theWindow[currentWindow]->portRect));
}
else {
ScrollBits();
}
}
VMathCommand()
{
float x, y, z;
char vValue[cmdWordLen];
SToR( command.cmdWord[1], &x, TRUE );
SToR( command.cmdWord[3], &y, TRUE );
if( strcmp(command.cmdWord[2],"+")==0 ) {
z = x + y;
}
else if( strcmp(command.cmdWord[2],"-")==0 ) {
z = x - y;
}
else if( strcmp(command.cmdWord[2],"*")==0 ) {
z = x * y;
}
else if( strcmp(command.cmdWord[2],"/")==0 ) {
if( NaN(&y) ) {
z=infinity;
}
else {
z = x / y;
}
}
else {
ErrMsg( noSuchModifier );
}
RToS(z, vValue);
if( !SetVar(command.cmdWord[5],vValue) ){
ErrMsg("couldnt create variable");
}
}